/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.Controller;

import com.DAO.CampoDAO;
import com.thoughtworks.xstream.XStream;
import java.util.List;
import javax.jws.WebMethod;
import javax.jws.WebService;

/**
 *
 * @author Fellipe
 */
@WebService(serviceName = "Campo")
public class Campo {

    private CampoDAO c = new CampoDAO();
    private XStream xstream = new XStream();
    
    @WebMethod(operationName = "create")
    public void createCampo(String xml) {
        
        c.create(fromXMLCampo(xml));
        
    }
    
    @WebMethod(operationName = "read")
    public String readCampo(int chaveCampo) {
        
        return toXMLCampo(c.read(chaveCampo));
        
    }
    
    @WebMethod(operationName = "readNomes")
    public String readNomesCampo() {
        
        return toXMLCampoList(c.readNomes());
        
    }
    
    @WebMethod(operationName = "update")
    public void updateCampo(String xml) {
        
        c.update(fromXMLCampo(xml));
        
    }
    
    @WebMethod(operationName = "delete")
    public void deleteCampo(int chaveCampo) {
        
        c.delete(chaveCampo);
        
    }
 
//Funções XML    
    private String toXMLCampo(com.Model.Campo campo) {
        
        return xstream.toXML(campo);
        
    }
    
    private String toXMLCampoList(List<com.Model.Campo> lista) {
        
        return xstream.toXML(lista);
        
    }

    private com.Model.Campo fromXMLCampo(String xml) {
        
        return (com.Model.Campo) xstream.fromXML(xml);
        
    }
    
}
